// TODO set tpl cache.
// TODO more path setup and error process.
dojo.provide("lotex.report.Dataset");

dojo.require("dojo.lang.declare");
dojo.require("dojo.event.*");
dojo.require("lotex.system.Loader");
dojo.require("lotex.system.AsynControler");

dojo.declare("lotex.report.Dataset", null, {
    initializer: function(data, define) {
        this.table = data;
        this.group = {};

        if (!dj_undef("group",define)) {
            var group = define.group;
            var len = group.length;
            for(var i=0;i<len;i++) {
                this.group[group[i].name] = this.groupby(group[i]);
            }
        }
    },

    getData: function(c) {
        var data = this.table.data;
        var len = data.length;
        var ret = [];
        for(var i=0;i<len;i++) {
            ret.push(data[i][c]);
        }
        return ret;
    },
/*        if (dj_undef("group",this)) {
            this.group = this.groupby();
        }*/
    groupby: function(fields){
        var tb = this.table;
        var d = tb.data;
        var len = d.length;

        var flag = [];
        var gc = 0;
        var group = [];
        flag[0] = d[0][0];
        flag[1] = d[0][1];
        group.push([]);
        group[gc].push(0);
        for(var i=1;i<len;i++){
            if(d[i][0] == flag[0] &&
               d[i][1] == flag[1]) {
                group[gc].push(i);
                continue;

            }
            flag[0] = d[i][0];
            flag[1] = d[i][1];
            gc++;
            group.push([]);
            group[gc].push(i);
        }
        //b(group,group[0]);
        return group;
    }
});

//dojo.lang.extend(dojo.iCalendar.Component, {